﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using System.Data.SqlClient;


namespace seminarska_SI
{
    public partial class AktivniAplikacii : Form
    {
        public AktivniAplikacii()
        {
            InitializeComponent();
            //Thread.Sleep(5000);
        }
        /*
        Process[] proces;
        Process[] proces1;
        private void ZemiProces()
        {
            proces = Process.GetProcesses();
            if (Convert.ToInt32(label2.Text) != proces.Length)
            {
                listBox1.Items.Clear();
                for (int i = 0; i < proces.Length; i++)
                {
                    listBox1.Items.Add(proces[i].ProcessName);
                }
                label2.Text = proces.Length.ToString();
            }


        }
        */

       

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //ZemiProces();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Monitor1();
            //ZemiProces();
            //ZemiBazaProcesi();
            
        }


        void Monitor1()
        {
            Process[] existingProcesses = Process.GetProcesses();
            
            bool doProcessing = true;
            while (doProcessing)
            {
                 Process[] currentProcesses = Process.GetProcesses();
                //var newProcesses = currentProcesses.Except(existingProcesses);

              


                //lb1.Items.Add(newProcesses);
                //foreach(String s in newProcesses)
               // {
               //     lb1.Items.Add(s);
               // }

                Thread.Sleep(5000); // Wait about 5 seconds before iterating again
            }
        }


        /*
        void ZemiBazaProcesi()
        {
            int i = 0;
            string[] procesi = new string[i];
            
            SqlConnection konekcija = new SqlConnection();
            konekcija.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\seminarska\\seminarska_SI\\Baza.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";

            string sqlString = "SELECT * FROM KillProcess";
            SqlCommand komanda = new SqlCommand(sqlString, konekcija);

            try
            {
                konekcija.Open();
                SqlDataReader citac = komanda.ExecuteReader();
                while (citac.Read())
                {
                    procesi[i] = citac["KillProcess"].ToString();
                    i++;
                }
                citac.Close();


                proces1 = Process.GetProcesses();
                if (Convert.ToInt32(label2.Text) != proces1.Length)
                {
                    listBox1.Items.Clear();
                    for (int i1 = 0; i1 < proces1.Length; i1++)
                    {
                        //listBox1.Items.Add(proces1[i].ProcessName);
                        for (int n1 = 0; n1 <= i; n1++)
                        {
                            string p = procesi[n1];
                            string p1 = proces[i1].ProcessName;
                           
                            if (p == p1)
                            {
                                proces1[i1].Kill();
                            }

                        }
                    }
                    label2.Text = proces1.Length.ToString();
                }


            }
            catch (Exception err)
            {

            }
            finally
            { 
                    konekcija.Close();
            }
            
        }
        */

        private void button1_Click(object sender, EventArgs e)
        {
            //proces[listBox1.SelectedIndex].Kill();
        }

        private void убијПроцесToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //proces[listBox1.SelectedIndex].Kill();
        }

    }
}
